import common.CommonFunction;
import common.Mask;

import mx.collections.ArrayCollection;
import mx.controls.Alert;
import mx.events.CloseEvent;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;



[Embed(source="/images/success.png")]private var successIcon:Class;
[Embed(source="/images/error.png")]private var errorIcon:Class;
[Embed(source="/images/question.png")]private var questionIcon:Class;



public var infoObject:Object;

public function onCreationComplete():void
{	
	infoObject = new Object();	
	infoObject["date"] = new Date();

	getBufferCustomers.send(infoObject);
	Mask.show(CommonFunction.getConstants('pleaseWait'));	
}

public var customerXML:XML;
public var customerList:ArrayCollection;
public function onSuccess(event:ResultEvent):void
{	
	Mask.close();	
	customerXML = event.result as XML;
	customerList = new ArrayCollection();
	for each(var obj:Object in customerXML.record)
	{			
		customerList.addItem({select:true,customerName:obj.customerName,phoneNumber:obj.phoneNumber,
		accountBal:obj.accountBal,gender:obj.gender,dob:obj.dob,geoLatitude:obj.geoLatitude,
		geoLongitude:obj.geoLongitude,address:obj.address,city:obj.city,
		state:obj.state,area:obj.area,country:obj.country,zipcode:obj.zipcode,
		customerImage:obj.customerImage,customerPanImage:obj.customerPanImage,voicePath:obj.voicePath,
		emailId:obj.emailId,imieNumber:obj.imieNumber});	
	}
	customerDetailsGrid.dataProvider = customerList;
}

public function onFailure(event:FaultEvent):void
{	
	Mask.close();	
	Alert.show("Connection Error..try Again");
}

public var customersList:ArrayCollection;
public function TrasferCustomers():void
{	
	customersList = new ArrayCollection();	
	for each (var obj:Object in customerDetailsGrid.dataProvider)
	{
		if(obj.select==true)
		{	
			customersList.addItemAt(obj.customerName,0);
			customersList.addItemAt(obj.accountBal,1);
			customersList.addItemAt(obj.phoneNumber,2);
			customersList.addItemAt(obj.dob,3);
			customersList.addItemAt(obj.gender,4);
			customersList.addItemAt(obj.geoLatitude,5);
			customersList.addItemAt(obj.geoLongitude,6);
			customersList.addItemAt(obj.address,7);
			customersList.addItemAt(obj.city,8);
			customersList.addItemAt(obj.state,9);			
			customersList.addItemAt(obj.area,10);
			customersList.addItemAt(obj.country,11);
			customersList.addItemAt(obj.zipcode,12);			
			customersList.addItemAt(obj.emailId,13);
			customersList.addItemAt(obj.imieNumber,14);			
		}
	}
	if(customersList.length==0)
	{	
		Alert.show(CommonFunction.getMessages('selectARecord'), CommonFunction.getMessages('error'), 0, null, null);
		
	}
	else 
	{	
		Alert.show(CommonFunction.getMessages('areyousure'), CommonFunction.getMessages('confirm'),
			(Alert.YES|Alert.NO), null, onValidation);		
	}
}

public function onValidation(event:CloseEvent):void
{	
	if(event.detail==Alert.YES)
	{	
		infoObject = new Object();
//		Alert.show(customersList.toString()+"");			
		infoObject["date"] = new Date();
		infoObject["selectedCustomers"] = customersList;
		Mask.show(CommonFunction.getMessages('pleaseWait'));	
		setCustomerMaster.send(infoObject);
	}	
}

public function onSuccessHandler(event:ResultEvent):void
{		
	if(event.result.booleanvalue=='true')
	{
		Alert.show(CommonFunction.getMessages('reqSuccess'), "Success");	
	}
	else
	{	
		Alert.show(CommonFunction.getConstants('reqFailure'), "Failure");	
	}
	getBufferCustomers.send(infoObject);
}